$(document).ready(function(){

/*This code will show and hide the sidebar menu.*/
  $("#hide_menu").click(function()
  					{   
  						$("#leftcolumn").hide();
						 $("#content").css({'margin-left':'0px'});
						 
						 
						 
    });
	 $("#show_menu").click(function()
  					{   
  						$("#leftcolumn").show();
						 $("#content").css({'margin-left':'220px'});
    });
    
  
  
});
///This code is for sidebar menu please do not delete it
$(document).ready(function () {
  $('#nav > li > a').click(function(){
    if ($(this).attr('class') != 'active'){
      $('#nav li ul').slideUp();
      $(this).next().slideToggle();
      $('#nav li a').removeClass('active');
      $(this).addClass('active');
    }
  });
});
////this function is for drop down popup for username and theme and alert
$(function() {
    $('#btnUser').click(function(fun){$('#box').toggle();});
    $('#box_inner').click(function(){return false;});
    $(this).click(function(fun){if(!($(fun.target).parent('#btnUser').length > 0)){ $('#box').hide();}
    });
	
	$('#btntheme').click(function(fun){$('#box1').toggle();});
    $('#box_inner1').click(function(){return false;});
    $(this).click(function(fun){if(!($(fun.target).parent('#btntheme').length > 0)){ $('#box1').hide();}
    });
	
	$('#btnalert').click(function(fun){$('#box2').toggle();});
    $('#box_inner2').click(function(){return false;});
    $(this).click(function(fun){if(!($(fun.target).parent('#btnalert').length > 0)){ $('#box2').hide();}
    });
	
	$('#btnemail').click(function(fun){$('#box3').toggle();});
    $('#box_inner3').click(function(){return false;});
    $(this).click(function(fun){if(!($(fun.target).parent('#btnemail').length > 0)){ $('#box3').hide();}
    });
});


/*Tab content jaquery function*/
$(document).ready(function() {

	$(".tab_content").hide();
	$(".tab_content:first").show(); 

	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();
		var activeTab = $(this).attr("rel"); 
		$("#"+activeTab).fadeIn(); 
	});
});
////////////
/////////////////////////////////////
/*
			TOOLTIP
		*/

		$( document ).ready( function()
		{
			var targets = $( '[rel~=tooltip]' ),
				target	= false,
				tooltip = false,
				title	= false;

			targets.bind( 'mouseenter', function()
			{
				target	= $( this );
				tip		= target.attr( 'title' );
				tooltip	= $( '<div id="tooltip"></div>' );

				if( !tip || tip == '' )
					return false;

				target.removeAttr( 'title' );
				tooltip.css( 'opacity', 0 )
					   .html( tip )
					   .appendTo( 'body' );

				var init_tooltip = function()
				{
					if( $( window ).width() < tooltip.outerWidth() * 1.5 )
						tooltip.css( 'max-width', $( window ).width() / 2 );
					else
						tooltip.css( 'max-width', 340 );

					var pos_left = target.offset().left + ( target.outerWidth() / 2 ) - ( tooltip.outerWidth() / 2 ),
						pos_top	 = target.offset().top - tooltip.outerHeight() - 20;

					if( pos_left < 0 )
					{
						pos_left = target.offset().left + target.outerWidth() / 2 - 20;
						tooltip.addClass( 'left' );
					}
					else
						tooltip.removeClass( 'left' );

					if( pos_left + tooltip.outerWidth() > $( window ).width() )
					{
						pos_left = target.offset().left - tooltip.outerWidth() + target.outerWidth() / 2 + 20;
						tooltip.addClass( 'right' );
					}
					else
						tooltip.removeClass( 'right' );

					if( pos_top < 0 )
					{
						var pos_top	 = target.offset().top + target.outerHeight();
						tooltip.addClass( 'top' );
					}
					else
						tooltip.removeClass( 'top' );

					tooltip.css( { left: pos_left, top: pos_top } )
						   .animate( { top: '+=10', opacity: 1 }, 50 );
				};

				init_tooltip();
				$( window ).resize( init_tooltip );

				var remove_tooltip = function()
				{
					tooltip.animate( { top: '-=10', opacity: 0 }, 50, function()
					{
						$( this ).remove();
					});

					target.attr( 'title', tip );
				};

				target.bind( 'mouseleave', remove_tooltip );
				tooltip.bind( 'click', remove_tooltip );
			});
		});

		/*
			---
		*/
		
		/*
		Master entry forms initially hidden all hide and show code are here
		*/
		$( document ).ready( function()
		{
			$(".form_placeholder").hide();
			$("#addSession").click(function(){ $("#session_add").show(300); $("#addSession").hide(200); });
			$("#cancel_session").click(function(){ $("#session_add").hide(300); $("#addSession").show(200);});
			
			$("#addCourse").click(function(){ $("#course_add").show(300); $("#addCourse").hide(200);});
			$("#cancel_course").click(function(){ $("#course_add").hide(300); $("#addCourse").show(200);});
			
			$("#addBranch").click(function(){ $("#branch_add").show(300); $("#addBranch").hide(200);});
			$("#cancel_branch").click(function(){ $("#branch_add").hide(300); $("#addBranch").show(200);});
			
			$("#addSubject").click(function(){ $("#subject_add").show(300); $("#addSubject").hide(200);});
			$("#cancel_subject").click(function(){ $("#subject_add").hide(300); $("#addSubject").show(200);});
			
			
			$("#addDepartment").click(function(){ $("#department_add").show(300); $("#addDepartment").hide(200); });
			$("#cancel_department").click(function(){ $("#department_add").hide(300); $("#addDepartment").show(200);});
			
			$("#addDesignation").click(function(){ $("#designation_add").show(300); $("#addDesignation").hide(200);});
			$("#cancel_designation").click(function(){ $("#designation_add").hide(300); $("#addDesignation").show(200);});
			
			$("#addqualification").click(function(){ $("#qualification_add").show(300); $("#addqualification").hide(200);});
			$("#cancel_qualification").click(function(){ $("#qualification_add").hide(300); $("#addqualification").show(200);});
			
			
			

		});
		
		/////Validation operation code hear
		
		$(document).ready(function() {
			// SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() }, 
			
			$("#form_session").validationEngine()
			$("#form_std_register").validationEngine()
			
			$("#btnSave_Session").click(function(){
				if($("#form_session").validationEngine({returnIsValid:true})){
					alert("hello")
				}else{
				}
				
				 $("#form_session").validationEngine({returnIsValid:true}); });
			
			$("#cancel_session").click(function(){ $.validationEngine.closePrompt(".formError",true) ; });
			//$.validationEngine.loadValidation("#date")
			//alert()
			//$.validationEngine.buildPrompt("#date","This is an example","error")	 		 // Exterior prompt build example								 // input prompt close example
			//$.validationEngine.closePrompt(".formError",true) 							// CLOSE ALL OPEN PROMPTS
		});
		
		// JUST AN EXAMPLE OF VALIDATIN CUSTOM FUNCTIONS : funcCall[validate2fields]
		function validate2fields(){
			if($("#firstname").val() =="" || $("#lastname").val() == ""){
				return true;
			}else{
				return false;
			}
		}